/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import utils.Weather;
import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;

/**
 *
 * @author Alberto, Alessandra
 */
@Entity
@NamedQuery(
            name = "findWeatherByName",
            query = "SELECT w FROM WeatherForecast w WHERE w.name = :Wname"
)
public class WeatherForecast implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;
    
    @NotNull(message = "May not be empty")
    private Weather name;
    
    @OneToMany(mappedBy = "weatherforecast")
    private Collection<OutdoorEvent> events;
    
    @ManyToMany(mappedBy = "badweather")
    private Collection<OutdoorEvent> badfor;

    public WeatherForecast () {
        
    }
    
    public WeatherForecast(Weather name) {
        this.name = name;
    }

    public Collection<OutdoorEvent> getBadfor() {
        return badfor;
    }

    public void setBadfor(Collection<OutdoorEvent> badfor) {
        this.badfor = badfor;
    }

    public Collection<OutdoorEvent> getEvents() {
        return events;
    }

    public void setEvents(Collection<OutdoorEvent> events) {
        this.events = events;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Weather getName() {
        return name;
    }

    public void setName(Weather name) {
        this.name = name;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final WeatherForecast other = (WeatherForecast) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }
    
    
    
}
